package top.plgxs.basic.one;

/**
 * <p> ==与equals() </p>
 *
 * @author Stranger.
 * @since 2022/9/1 14:51
 */
public class Equals {
    public String name;

    public static void main(String[] args) {
        // == 基本类型比较值，引用类型比较内存地址

        // equals 没有重写比较内存地址 重写比较对象内容

        Integer i = 128;
        Double j = Double.valueOf(128);
        System.out.println( i.equals(j));

        String name1 = "abc";
        String name2 = "abc";
        String name3 = "abcd";
        String name4 = name1 + "d";
        String name5 = new String("abcd");
        System.out.println(name1 == name2);
        System.out.println(name1.equals(name2));
        System.out.println(name3 == name4);
        System.out.println(name3 == name5);

        Equals e1 = new Equals();
        Equals e2 = new Equals();
        e1.name = new String("abc");
        e2.name = "abc";
        System.out.println(e1 == e2);
        System.out.println(e1.equals(e2));
    }

}
